package util;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import entity.Cargo;
import entity.Cidade;
import entity.Cliente;
import entity.Compra;
import entity.CondicaoPagamento;
import entity.ContasPagar;
import entity.ContasReceber;
import entity.Estado;
import entity.FormaPagamento;
import entity.Fornecedor;
import entity.Funcionario;
import entity.Marca;
import entity.Medico;
import entity.OrdemServico;
import entity.Pais;
import entity.Produto;
import entity.TipoProduto;
//import entity.ContasPagar;
//import entity.ContasReceber;



public class HibernateUtil {

    private static SessionFactory sessionFactory;

    private HibernateUtil() {
        
    }

    public static SessionFactory getSessionFactory() {

        if (sessionFactory == null) {
            try {
                AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
                annotationConfiguration.addAnnotatedClass(Pais.class);
                annotationConfiguration.addAnnotatedClass(Estado.class);
                annotationConfiguration.addAnnotatedClass(Cidade.class);
                annotationConfiguration.addAnnotatedClass(Cargo.class);
                annotationConfiguration.addAnnotatedClass(Cliente.class);
                annotationConfiguration.addAnnotatedClass(Compra.class);
                annotationConfiguration.addAnnotatedClass(CondicaoPagamento.class);
                annotationConfiguration.addAnnotatedClass(FormaPagamento.class);
                annotationConfiguration.addAnnotatedClass(ContasPagar.class);
                annotationConfiguration.addAnnotatedClass(ContasReceber.class);
                annotationConfiguration.addAnnotatedClass(Fornecedor.class);
                annotationConfiguration.addAnnotatedClass(Funcionario.class);
                annotationConfiguration.addAnnotatedClass(Marca.class);
                annotationConfiguration.addAnnotatedClass(Produto.class);
                annotationConfiguration.addAnnotatedClass(TipoProduto.class);
                annotationConfiguration.addAnnotatedClass(Medico.class);
                annotationConfiguration.addAnnotatedClass(OrdemServico.class);

                sessionFactory = annotationConfiguration.configure().buildSessionFactory();

            } catch (Throwable ex) {
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }

            return sessionFactory;

        } else {
            return sessionFactory;
        }
        
    }
}
